function [MC, par, grid]=get_parameterization
% Copyright (C) 2021-2023 Benjamin Born, Francesco D'Ascanio, Gernot J. Mueller, Johannes Pfeifer
%
% This is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% It is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
% GNU General Public License for more details.
% 
% For a copy of the GNU General Public License,
% see <http://www.gnu.org/licenses/>.

MC.A =[0.88 -0.42 0;
    -0.05 0.59 0
    0        0     0.924];

MC.Sigma = [0.000536  -0.000010 0
    -0.000010  0.000060  0
    0           0         0.0228^2];

MC.omicron= chol(MC.Sigma,'lower');
par.mu_g=0.2123*1.2; %account for g share being in total output
par.rho_g=MC.A(3,3);
par.sigma_g=sqrt(MC.Sigma(3,3));

% Set parameters to simulate time series below (discretization as in SGU)
MC.T=5000000; % simulation periods
MC.Tburn=10000; % periods that are discarded

% Discretization of stochastic process for (lnyt_t, ln(1+r_t)/(1+r)),: (taken from SGU 2009) trim pairs which occur
% with probability 0

grid.NY = 7; % gridpoints for yt (21 in SGU)
grid.NR = 5; % gridpoints for r (11 in SGU)
grid.NG = 9; % gridpoints for g
% grid.NY = 3; % gridpoints for yt (21 in SGU)
% grid.NR = 3; % gridpoints for r (11 in SGU)
% grid.NG = 5; % gridpoints for g

grid.N=[grid.NY grid.NR grid.NG]';
% [MC.P_trans,MC.S] = tpm(MC.A,MC.omicron,grid.N,MC.T,MC.Tburn,[],1);

%% 
[P_trans_Yr,S_Yr] = tpm(MC.A(1:2,1:2),MC.omicron(1:2,1:2),grid.N(1:2),MC.T,MC.Tburn,[],1);
%% do analytical approximation for G and impose orthogonality via Kronecker product
[G_states,Gprob]=tauchenhussey(grid.NG,par.mu_g,par.rho_g,par.sigma_g,par.sigma_g);
MC.S=[repmat(S_Yr,grid.NG,1) kron(G_states,ones(length(S_Yr),1))];
MC.P_trans=kron(Gprob,P_trans_Yr);

grid.y=MC.S(:,1);
grid.r=MC.S(:,2);
grid.g_level=MC.S(:,3); %already in level-form
%ygrid vector of grid points for the log of the tradable endowment
%rgrid grid points for interest rate expressed as log((1+r_t)/(1+r^*))
%produced by running tpm.m

grid.n_y = numel(grid.y); %number of grid points for exogenous states
grid.y_level = exp(grid.y(:)); %level of tradable output

par.rstar = 0.011;
grid.r_level = exp(grid.r)*(1+par.rstar)-1; %interest rate in level

par.betta = 0.9375;% %discount factor
par.sigg = 5; %consumption elasticity of marginal utility of consumption (Reinhart and Vegh, JDE 1995)
par.alfa = 0.75;%labor share in nontraded sector  (Uribe, JME1997)
par.hbar = 1;  %full-employment hours6
par.omega = 0.37;%Share parameter in Armington aggregator
par.xi = 0.44;% Elasticity of substitution between traded and nontraded goods
par.gama = 0.9982/(1.003*1.003); %degree of nominal wage rigidity (SGU estimate)

grid.n_w = 800; %number of grid points past real wage
%wage grid
w_upper = 7.5;
w_lower = 1;
w_grid_vec = log(w_lower):(log(w_upper)-log(w_lower))/(grid.n_w-1):log(w_upper);
grid.w_grid_vec = exp(w_grid_vec(:));
grid.w_grid_step_size  = log(grid.w_grid_vec(2)) - log(grid.w_grid_vec(1));

par.d_bar_natural=0.99*min(grid.y_level)*(1+max(grid.r_level))/max(grid.r_level);
grid.n_d = 501;% # of grid points for debt, d_t
%debt grid
d_upper = par.d_bar_natural;
d_lower = 8;
grid.d_grid = linspace(d_lower,d_upper,grid.n_d)';

par.phi_w = -0.2*par.mu_g;
end